package drawingtools;
import program.*;

import gui.DrawingPanel;

import java.awt.event.MouseEvent;

import diagramobjects.BorderAreaUses;
import diagramobjects.DiagramObject;
import diagramobjects.DiagramObjects;
import diagramobjects.Actor;

import program.DatabaseConnection;


public class BorderAreaUsesTool extends DrawingTool{
	
	private DiagramObjects GeomObjs;
	private DiagramObject tempObject;
	private DrawingPanel DrawPanel;
	
	public BorderAreaUsesTool(DiagramObjects go, DrawingPanel dp)
	{
		GeomObjs = go;
		DrawPanel = dp;
	}
	
	
	@Override
	/**
	 * Reaguje na klikniecie na panelu, 
	 * jesli ClickCount = 0 - poczatek tworzenia
	 * 			dodaje linie do panelu, 
	 * 			odniesienie zapisuje pod tempLine - mozna przesuwac teraz tempLine
	 * 			dodaje tempLine do BD
	 * jesli cliccount == 1
	 * 			zeruje clickcount
	 */
	public void mousePressed(MouseEvent arg0) {
		super.mousePressed(arg0);
		System.out.println("mouseClicked, clickcount:" + ClickCount);

		{
			GeomObjs.AddGeometricObjectToPanel(new BorderAreaUses("Text", arg0.getX(), arg0.getY()));
			DrawPanel.addSelected();
			tempObject = GeomObjs.GetLastGeometricbjectFromPanel();
			//((Line)tempObject).Print();
			IncreaseClickCount();
			//DatabaseConnection.AddUseCase(tempObject.ToDatabase());
			DrawPanel.repaint();

		}
		/*else if (ClickCount == 1)
		{
			ZeroClickCount();
			
		}*/

	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		super.mouseReleased(arg0);
		System.out.println("UseCaseTool->mouseReleased(MouseEvent e)");
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		super.mouseDragged(e);
		System.out.println("UseCaseTool->mouseDragged(MouseEvent e)");
		
		
		Double sizex = new Double(e.getX() - tempObject.getPositionX());
		Double sizey = new Double(e.getY() - tempObject.getPositionY());
		if (sizex <0)
			sizex = 0.0;
		if (sizey < 0)
			sizey = 0.0;
		
		//if (sizex>sizey)
		//sizey = 2*sizex;
		//else
			//sizex = 1.4*sizey;
			
		//tempObject.SetSize(sizex.intValue(), sizey.intValue());
		
		tempObject.SetSize(sizex.intValue(), sizey.intValue());
		//Double textsize = java.lang.Math.sqrt(java.lang.Math.sqrt((sizex*sizex*sizex+sizey*sizey)));
		//textsize *= 0.5;
		//tempObject.SetTextSize( textsize.intValue());
		tempObject.Print();
		DrawPanel.repaint();
		

	}


	
	
}
